from page.net_project_page import NetProjectPage
from common.page import IOS
import time as t

class XinItemPage(NetProjectPage):
    # 客观题列表页面
    stage_selected = (IOS, 'type == "XCUIElementTypeStaticText" AND label CONTAINS "客观题 |"')  # 选择阶段
    not_submit = (IOS, 'type == "XCUIElementTypeButton" AND label == "去答题"')
    # 客观题答题页面
    answer_A = (IOS, 'type == "XCUIElementTypeButton" AND label == "A"')
    answer_B = (IOS, 'type == "XCUIElementTypeButton" AND label == "B"')
    answer_C = (IOS, 'type == "XCUIElementTypeButton" AND label == "C"')
    confirm_answer = (IOS, 'type == "XCUIElementTypeButton" AND label == "确定"')
    submit_item_btn = (IOS, 'type == "XCUIElementTypeButton" AND label == "提交"')
    view_wrong = (IOS, 'type == "XCUIElementTypeOther" AND name == "我的错题"')
    again_btn = (IOS, 'type == "XCUIElementTypeButton" AND label == "重新答题"')
    error = (IOS,'type == "XCUIElementTypeStaticText" AND name CONTAINS "常见的手持设备系统主要 |"')
    # def select_answer(self):
    #     self.swipe_dr('up')
    #     try:
    #         # self.find_element(*self.confirm_answer,times=3)
    #         self.find_element(*self.answer_B).click()
    #         self.find_element(*self.confirm_answer).click()
    #     except Exception:
    #
    #         self.swipe_dr('down')
    #         self.find_element(*self.answer_A).click()
    #     # else:
    #         self.find_element(*self.answer_B).click()
    #         self.find_element(*self.confirm_answer).click()

    def submit_item(self, item_count=10):    #苹果6

        self.find_element(*self.not_submit).click()
        for i in range(item_count):
            # self.select_answer()
            self.swipe_dr('up')
            self.find_button(string="B",contains_flag=1).click()
            # self.find_element(*self.answer_B).click()
            try:
                # self.find_element(*self.confirm_answer,times=3)
                # self.find_element(*self.answer_B).click()
                # self.find_element(*self.confirm_answer).click()
                self.find_button(string="确定",contains_flag=1).click()
            except Exception:
                continue
                # self.swipe_dr('down')
                # self.find_element(*self.answer_A).click()
                # # else:
                # self.find_element(*self.answer_B).click()
                # self.find_element(*self.confirm_answer).click()

        self.find_element(*self.submit_item_btn).click()
        t.sleep(3)
        # self.swipe_dr('down')
        self.swipe(150,66,150,66)
        t.sleep(0.5)
        self.find_element(*self.view_wrong).click()
        t.sleep(1)
        # for i in range(4):
        #     self.swipe_dr('left')
        self.swipe_dr('up')
        self.swipe(60, 450, 60, 450)
        # self.find_element(*self.error).click()
        t.sleep(1)
        self.find_button(string="返回", contains_flag=1).click()
        self.find_button(string="返回", contains_flag=1).click()
        self.find_button(string="返回",contains_flag=1).click()


    def submit_items(self):   #苹果6s

        self.find_element(*self.not_submit).click()
        for i in range(10):
            # self.select_answer()
            self.swipe_dr('up')
            self.find_element(*self.answer_B).click()
            try:
                # self.find_element(*self.confirm_answer,times=3)
                # self.find_element(*self.answer_B).click()
                self.find_button(string='确定', contains_flag=1).click()
            except Exception:
                continue


        self.find_element(*self.submit_item_btn).click()
        t.sleep(3)
        # self.swipe_dr('down')
        self.swipe(150,66,150,66)
        t.sleep(0.5)
        self.find_element(*self.view_wrong).click()
        t.sleep(1)
        # for i in range(4):
        #     self.swipe_dr('left')
        self.swipe_dr('up')
        self.swipe(60, 450, 60, 450)
        # self.find_element(*self.error).click()
        self.find_button(string="返回", contains_flag=1).click()
        self.find_button(string="返回", contains_flag=1).click()
        self.find_button(string="common back light icon",contains_flag=1).click()


if __name__ == '__main__':
    test = XinItemPage()
    test.enter_project()
    test.enter_tools("客观题")
    # test.submit_item()
    test.submit_items()
